/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao.authentification;

import authentification.Exception.AuthException;
import authentification.entitie.UserAuth;
import authentification.service.Authentification;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author loic.vaugeois
 */
@ManagedBean
@RequestScoped
public class TestAuthentification {

    @EJB
    private Authentification authentification;

    /** Creates a new instance of TestProposition */
    public TestAuthentification() {
    }

    public void tester(){
        testProposition();
        System.out.println("-------------------------------------------------------------------");
    }

    private void testProposition() {
        System.out.println("test Authentification");
        System.out.println("TEST 1: Doit Etre bon et renvoyé le descriptif du User:");
        try {
            UserAuth user = authentification.validUser("loic.vaugeois", "123456");
            if (user!=null) {                
                System.out.println("Nom: " + user.getNom());
                System.out.println("Prenom: " + user.getPrenom());
                System.out.println("Login: " + user.getLogin());
                System.out.println("Test ok! le password est bon.");
            }            
        } catch (AuthException ex) {
            System.err.println("AuthException : " + ex.getClass().toString());
        }
        System.out.println("TEST 2: Doit Etre faux et renvoyé une AuthException:");
        try{
        UserAuth user2 = authentification.validUser("loic.vaugeois", "123123");
            if (user2!=null) {
                System.out.println("Nom: " + user2.getNom());
                System.out.println("Prenom: " + user2.getPrenom());
                System.out.println("Login: " + user2.getLogin());
            }
            System.err.println("Erreur d'authentification! ");
        } catch (AuthException ex) {
            System.out.println("AuthException : " + ex.getClass().toString());
        }
        System.out.println("TEST 3: Doit Etre faux et renvoyé une AuthException:");
        try{
        UserAuth user2 = authentification.validUser("loic.loic", "123456");
            if (user2!=null) {
                System.out.println("Nom: " + user2.getNom());
                System.out.println("Prenom: " + user2.getPrenom());
                System.out.println("Login: " + user2.getLogin());
            }
            System.err.println("Erreur d'authentification! ");
        } catch (AuthException ex) {
            System.out.println("AuthException : " + ex.getClass().toString());
        }
    }
}
